-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve 2022 day 02 #13
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented on part 1, where do I see the problem definition for part 2?
puzzles/solutions/2022/d02/p1.py
Outdated
def get_moves(input_text: str) -> list[tuple[str, str]]: | ||
""" | ||
:param input_text: puzzle input | ||
:return: list of (opponent move, our move) couples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the term "pair" instead of "couple".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 583c923.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the same for all other places "couple" is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I miss any in that day's solutions?
puzzles/solutions/2022/d02/shapes.py
Outdated
OPPONENT_PAPER = "B" | ||
OPPONENT_SCISSORS = "C" | ||
|
||
OUR_TO_OPPONENT_SHAPE_DEFEAT = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The different dictionaries here have different logical levels of abstractions.
The first two tell you what is the defeating shape, i.e., it is in the level of the general rock-paper-scissors game.
The third one tells you what input characters are the same shape, i.e., it is in the level of the definition of the problem's input -- not actually related to the game.
The fourth one tells you what the score is for each shape, i.e., it is in the level of the rock-paper-scissors tournament -- one level above the general game. Additional inconsistency is that some scores are defined here as a constant, and others are defined in the code itself.
I suggest you separate the levels of abstraction more clearly:
- First, parse the problem input into some object describing the rock-paper-scissors game. Note that you don't really need to continue with the "our" and "opponent" shape distinction: If you represent a turn as a pair of shapes (our, opponent), you can use the same object for "our" and for "opponent" rock.
- Define a function which reports the result of the turn, at the level of the rock-paper-scissors game -- So nothing about scores yet. This function can be a dictionary with all possible turns as keys are the corresponding values representing the result in some way.
- Define a function which reports the score of the turn, at the level of the rock-paper-scissors tournament, based on the turn pair (from step 1) and the turn's result (from step 2).
It unlocks after solving part 1, so I'll paste it here:
|
puzzles/solutions/2022/d02/p2.py
Outdated
import shapes | ||
|
||
|
||
DEFEAT = "X" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda lousy that you have a shapes
modules for constants, where you define OUR_ROCK = "X"
, but also define DEFEAT = "X"
here.
puzzles/solutions/2022/d02/p2.py
Outdated
if outcome == DEFEAT: | ||
return shapes.OPPONENT_TO_OUR_SHAPE_DEFEAT[opponent_move] | ||
if outcome == DRAW: | ||
for our_shape, opponent_shape in shapes.IDENTICAL_SHAPES.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This for-loop means that you should have an inverted version of the IDENTICAL_SHAPES
dictionary.
583c923
to
1195c53
Compare
Previously the function gave the desired shape as if the given shape was ours and not the opponent's.
1195c53
to
bc6f747
Compare
I made quite a few changes, see what you think now.
I decided to leave a for-loop in |
74812ad
to
768d850
Compare
This module contains now more constants than just shapes, so a name change is desired.
768d850
to
8439278
Compare
No description provided.